package frontend.parser.syntaxtree;

import frontend.lexer.TKType;
import frontend.parser.syntaxtree.symbol.NonTerminalSymbol;
import frontend.parser.syntaxtree.symbol.TerminalSymbol;

import java.util.function.Consumer;

public class StmtNodeForLoop extends StmtNode {
    public ForStmtNode forStmt1;
    public CondNode cond;
    public ForStmtNode forStmt2;
    public StmtNode stmt;

    @Override
    public void walk(Consumer<TerminalSymbol> terConsumer, Consumer<NonTerminalSymbol> nonTerConsumer) {
        terConsumer.accept(new TerminalSymbol(TKType.FORTK));
        terConsumer.accept(new TerminalSymbol(TKType.LPARENT));

        if (forStmt1 != null) {
            forStmt1.walk(terConsumer, nonTerConsumer);
        }

        terConsumer.accept(new TerminalSymbol(TKType.SEMICN));

        if (cond != null) {
            cond.walk(terConsumer, nonTerConsumer);
        }

        terConsumer.accept(new TerminalSymbol(TKType.SEMICN));

        if (forStmt2 != null) {
            forStmt2.walk(terConsumer, nonTerConsumer);
        }

        terConsumer.accept(new TerminalSymbol(TKType.RPARENT));

        stmt.walk(terConsumer, nonTerConsumer);

        nonTerConsumer.accept(new NonTerminalSymbol(this));
    }
}
